package com.dream21th.rule.engine.biz;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dream21th.common.dto.PageDTO;
import com.dream21th.rule.engine.entity.DroolsBaseInfo;
import com.dream21th.rule.engine.service.DroolsBaseInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;

@Slf4j
@Component
public class DroolsBaseBiz {

    @Autowired
    private DroolsBaseInfoService droolsBaseInfoService;

    public IPage<DroolsBaseInfo> droolsPage(PageDTO<DroolsBaseInfo> pageDTO){
        IPage<DroolsBaseInfo> page = new Page(pageDTO.getCurrent(),pageDTO.getSize());
        return droolsBaseInfoService.page(page,  Wrappers.lambdaQuery(pageDTO.getParam()));
    }

    public DroolsBaseInfo selectOneDrools(DroolsBaseInfo droolsBaseInfo){
        return droolsBaseInfoService.getOne(Wrappers.lambdaQuery(droolsBaseInfo),false);
    }

    public Boolean updateOrSaveOneDrools(DroolsBaseInfo droolsBaseInfo){
        if(Objects.isNull(droolsBaseInfo.getId())){
            return droolsBaseInfoService.save(droolsBaseInfo);
        }
        return droolsBaseInfoService.updateById(droolsBaseInfo);
    }

    public Boolean deleteDrools(List<Integer> ids){
        return droolsBaseInfoService.removeByIds(ids);
    }
}
